---------------------------------------------------------------------
-- 外观配色 + tabline
-- 作者: 忘羽梦汐
-- 功能: 配色方案、光标、鼠标逻辑、集成tabline.wez主题
---------------------------------------------------------------------

local wezterm = require("wezterm")
local Config = require("config")

-- 初始化事件
require("events.right-status")
require("events.tab-title").setup()
require("events.new-tab-button").setup()

-- 引入 tabline.wez 插件
local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez")

---------------------------------------------------------------------
-- 颜色方案
---------------------------------------------------------------------
local COLOR_SCHEME = {
	BASE = { foreground = "#FFFFFF", background = "#1a1b26" },
	CURSOR = { bg = "#32CD32", fg = "#1a1b26", border = "#c0caf5" },
	SELECTION = { fg = "#1a1b26", bg = "#c0caf5" },
	TAB_BAR = {
		background = "#FFFF00",
		active_tab = { bg_color = "#FFFF00", fg_color = "#7dcfff" },
		inactive_tab = { bg_color = "#1a1b26", fg_color = "#565f89" },
		inactive_tab_hover = { bg_color = "#24283b", fg_color = "#7aa2f7" },
		new_tab = { bg_color = "#1a1b26", fg_color = "#c0caf5" },
		new_tab_hover = { bg_color = "#414868", fg_color = "#7dcfff" },
	},
	UI = { scrollbar_thumb = "#414868", split = "#16161e" },
	ANSI = { "#15161e", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#a9b1d6" },
	BRIGHTS = { "#414868", "#f7768e", "#9ece6a", "#e0af68", "#7aa2f7", "#bb9af7", "#7dcfff", "#c0caf5" },
}

---------------------------------------------------------------------
-- 构建基础配置
---------------------------------------------------------------------
local base_config = Config:init()
	:append(require("config.appearance"))
	:append(require("config.bindings"))
	:append(require("config.domains"))
	:append(require("config.fonts"))
	:append(require("config.general"))
	:append(require("config.launch")).options

-- 应用颜色方案
base_config.colors = {
	foreground = COLOR_SCHEME.BASE.foreground,
	background = COLOR_SCHEME.BASE.background,
	cursor_bg = COLOR_SCHEME.CURSOR.bg,
	cursor_fg = COLOR_SCHEME.CURSOR.fg,
	cursor_border = COLOR_SCHEME.CURSOR.border,
	selection_fg = COLOR_SCHEME.SELECTION.fg,
	selection_bg = COLOR_SCHEME.SELECTION.bg,
	tab_bar = COLOR_SCHEME.TAB_BAR,
	scrollbar_thumb = COLOR_SCHEME.UI.scrollbar_thumb,
	split = COLOR_SCHEME.UI.split,
	ansi = COLOR_SCHEME.ANSI,
	brights = COLOR_SCHEME.BRIGHTS,
}

-- 鼠标右键粘贴
base_config.mouse_bindings = base_config.mouse_bindings or {}
table.insert(base_config.mouse_bindings, {
	event = { Up = { streak = 1, button = "Right" } },
	mods = "NONE",
	action = wezterm.action.PasteFrom("Clipboard"),
})

---------------------------------------------------------------------
-- 启用 tabline 插件
---------------------------------------------------------------------
tabline.setup({
	options = {
		icons_enabled = true,
		theme = "GruvboxDark",
		section_separators = {
			left = wezterm.nerdfonts.pl_left_hard_divider,
			right = wezterm.nerdfonts.pl_right_hard_divider,
		},
		component_separators = {
			left = wezterm.nerdfonts.pl_left_soft_divider,
			right = wezterm.nerdfonts.pl_right_soft_divider,
		},
	},
	sections = {
		tabline_a = { "mode" },
		tabline_b = { "workspace" },
		tabline_c = { " " },
		tab_active = {
			"index",
			{ "parent", padding = 0 },
			"/",
			{ "cwd", padding = { left = 0, right = 1 } },
			{ "zoomed", padding = 0 },
		},
		tab_inactive = { "index", { "process", padding = { left = 0, right = 1 } } },
		tabline_x = { "ram", "cpu" },
		tabline_y = { "datetime", "battery" },
		tabline_z = { "domain" },
	},
	extensions = {},
})

return base_config
